package com.cloudpan.common;

import cn.hutool.core.io.FileUtil;

import java.util.Arrays;
import java.util.List;

public class MinetypeConstant {
    public static final List<String> MINETYPE_DOCUMENT = Arrays.asList(new String[]{"doc", "docx", "ppt", "pptx", "xls", "xlsx", "txt", "hlp", "wps", "rtf", "pdf", "md"});
    public static final List<String> MINETYPE_VIDEO = Arrays.asList(new String[]{"avi", "mp4", "mpg", "mov", "swf", "flv"});
    public static final List<String> MINETYPE_IMAGE = Arrays.asList(new String[]{"bmp", "jpg", "png", "tif", "gif", "jpeg"});
    public static final List<String> MINETYPE_MUSIC = Arrays.asList(new String[]{"wav", "aif", "au", "mp3", "ram", "wma", "mmf", "amr", "aac", "flac"});
    public static final List<String> MINETYPE_EXE = Arrays.asList(new String[]{"exe", "app", "deb", "rpm", "ipa", "dmg", "apk"});


    //通过该方法快速获取文件类型
    //1:视频 2:音频 3:图片 4:pdf 5:doc 6:excel 7:txt 8:code 9:zip 10:其他
    public static String getContentType(String FilenameExtension) {
        if (MinetypeConstant.MINETYPE_VIDEO.contains(FilenameExtension)){
            return CommonConstants.FILETYPE_VIDEO;
        }
        if (MinetypeConstant.MINETYPE_MUSIC.contains(FilenameExtension)){
            return CommonConstants.FILETYPE_AUDIO;
        }
        if (MinetypeConstant.MINETYPE_IMAGE.contains(FilenameExtension)){
            return CommonConstants.FILETYPE_PICTURE;
        }
        if (FileUtil.getSuffix(FilenameExtension).equals("pdf")){
            return CommonConstants.FILETYPE_PDF;
        }
        if (FileUtil.getSuffix(FilenameExtension).equals("xls")
                || FileUtil.getSuffix(FilenameExtension).equals("xlsx")){
            return CommonConstants.FILETYPE_EXCEL;
        }
        if (FileUtil.getSuffix(FilenameExtension).equals("doc")
                || FileUtil.getSuffix(FilenameExtension).equals("docx")){
            return CommonConstants.FILETYPE_DOC;
        }
        if (FileUtil.getSuffix(FilenameExtension).equals("txt")){
            return CommonConstants.FILETYPE_TXT;
        }
        if (FileUtil.getSuffix(FilenameExtension).equals("java")
                || FileUtil.getSuffix(FilenameExtension).equals("py")
                || FileUtil.getSuffix(FilenameExtension).equals("c")
                || FileUtil.getSuffix(FilenameExtension).equals(".html")
                || FileUtil.getSuffix(FilenameExtension).equals(".xml")){
            return CommonConstants.FILETYPE_CODE;
        }
        return CommonConstants.FILETYPE_OTHER;
    }
    //1:视频 2:音频 3:图片 4:文档 5:其他
    public static String getFileCategory(String FilenameExtension){
        if (MinetypeConstant.MINETYPE_VIDEO.contains(FilenameExtension)){
            return CommonConstants.CATEGORY_VIDEO;
        }
        if (MinetypeConstant.MINETYPE_MUSIC.contains(FilenameExtension)){
            return CommonConstants.CATEGORY_AUDIO;
        }
        if (MinetypeConstant.MINETYPE_IMAGE.contains(FilenameExtension)){
            return CommonConstants.CATEGORY_PICTURE;
        }
        if (MinetypeConstant.MINETYPE_DOCUMENT.contains(FilenameExtension)){
            return CommonConstants.CATEGORY_DOCUMENT;
        }
        return CommonConstants.CATEGORY_OTHER;
    }
}
